<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>简单路由的实现</title>
</head>
<body>
    <div id="app">
        <a href="#/index">首页</a>
        <a href="#/sport">运动</a>
        <a href="#/education">教育</a>

        <div>
            <compoent :is="component_name"></compoent>
        </div>
    </div>
</body>
<script src="vue.js"></script>
<script>
    const app = new Vue({
        el: "#app",
        data: {
            component_name: 'index'
        },
        components: {
            index: {
                template: `<div>I am index</div>`
            },
            sport: {
                template: `<div>I am sport</div>`
            },
            education: {
                template: `<div>I am education</div>`
            },
        }
    });
    window.onhashchange = function(){
        Vue.set(app, 'component_name', location.hash.replace("#/", ""))
    }
</script>
</html>